//
// Created by hsj on 2022/1/18.
//

#include <iostream>
#include "t_queue.h"
namespace hsj_queue{
    //成员初始化列表【构造函数可用】，被声明引用的成员必须这样初始化
    //非静态const 和 引用只有在被创建时候才会初始化（c++11之前强制，c++11之后放宽限制）
    Queue::Queue(int qs):qsize(qs){
      front = rear = NULL;// nullptr
      items = 0;
    }

    bool Queue::enqQueue(const Item &item){
        if (isFull()){
            return false;
        }
        Node *add  = new Node;
        add->item = item;
        add->next = NULL;
        ++items;
        if (front == NULL){
            front = add;
        }
        else{
            rear->next = add;
        }
        rear = add;
        return true;
    }

    bool Queue::deQueue(Item &item){
        if (front == NULL){
            return false;
        }
        item = front->item;
        --items;
        Node *temp = front;
        front = front->next;
        delete temp;
        if (items == 0){
            rear = NULL;
        }
        return true;
    }

    bool Queue::isEmpty()const{
        return items == 0;
    }

    bool Queue::isFull() const{
        return items == qsize;
    }

    int Queue::queueCount() const{
        return items;
    }

    Queue::~Queue(){
        Node *temp;
        while (front != NULL){
            temp = front;
            front = front->next;
            delete temp;
        }
    }


    void Customer::set(long when){
        processTime = std::rand() % 3 + 1;
        arrive = when;
    }

}